﻿Imports Microsoft.Xna.Framework

Namespace Global.Runa.Resources.ContentReader.VectorFont

    Public Class VectorFontCharacter

#Region "struct Outline"

        ''' <summary>Stores the starting index and the vertex count of a character outline</summary>
        Public Structure Outline

            ''' <summary>Initializes a new character outline</summary>
            ''' <param name="startVertexIndex">Index of the vertex with which the outline starts</param>
            ''' <param name="vertexCount">Number of vertices in this outline</param>
            Public Sub New(startVertexIndex As Integer, vertexCount As Integer)
                Me.StartVertexIndex = startVertexIndex
                Me.VertexCount = vertexCount
            End Sub

            ''' <summary>Index of the vertex with which the outline begins</summary>
            Public StartVertexIndex As Integer
            ''' <summary>Total number of vertices the outline consists of</summary>
            Public VertexCount As Integer

        End Structure

#End Region

#Region "struct Face"

        ''' <summary>Stores three vertex indices forming a triangle</summary>
        Public Structure Face

            ''' <summary>Initializes a new character face triangle</summary>
            ''' <param name="firstVertexIndex">Index of the triangle's first vertex</param>
            ''' <param name="secondVertexIndex">Index of the triangle's second vertex</param>
            ''' <param name="thirdVertexIndex">Index of the triangle's third vertex</param>
            Public Sub New(firstVertexIndex As Integer, secondVertexIndex As Integer, thirdVertexIndex As Integer)
                Me.FirstVertexIndex = firstVertexIndex
                Me.SecondVertexIndex = secondVertexIndex
                Me.ThirdVertexIndex = thirdVertexIndex
            End Sub

            ''' <summary>Index of the first vertex of the triangle</summary>
            Public FirstVertexIndex As Integer
            ''' <summary>Index of the second vertex of the triangle</summary>
            Public SecondVertexIndex As Integer
            ''' <summary>Index of the third vertex of the triangle</summary>
            Public ThirdVertexIndex As Integer
        End Structure

#End Region

        ''' <summary>Initializes new vector font character</summary>
        ''' <param name="advancement">
        '''   By what to advance the pen after the character was drawn
        ''' </param>
        ''' <param name="vertices">Vertices used by this character</param>
        ''' <param name="outlines">Vertex indices for drawing the character's outline</param>
        ''' <param name="faces">Vertex indices for filling the character</param>
        Friend Sub New(advancement As Vector2, vertices As List(Of Vector2), outlines As List(Of Outline), faces As List(Of Face))
            Me.m_advancement = advancement
            Me.m_vertices = vertices
            Me.m_outlines = outlines
            Me.m_faces = faces
        End Sub

        ''' <summary>By how much to advance the cursor after drawing this character</summary>
        Public ReadOnly Property Advancement() As Vector2
            Get
                Return Me.m_advancement
            End Get
        End Property

        ''' <summary>Vertices for this character</summary>
        ''' <remarks>
        '''   This contains the vertices required to draw the outline of the character
        '''   as well as supporting vertices required to draw the character's face as
        '''   a series of triangles. If you're only interested in a character's outlines,
        '''   you can ignore any vertices with an index above the EndVertex of
        '''   the lastmost outline contained in the Outlines list.
        ''' </remarks>
        Public ReadOnly Property Vertices() As List(Of Vector2)
            Get
                Return Me.m_vertices
            End Get
        End Property

        ''' <summary>
        '''   Specifies which vertices have to be connected to draw the outlines
        '''   of the character.
        ''' </summary>
        ''' <remarks>
        '''   <para>
        '''     A character can have more than one outline. For example, the equals sign ('=')
        '''     has two unconnected shapes that require two outlines to be drawn. In this
        '''     case, you'd find two outlines, the first one specifying the starting and ending
        '''     vertex for the first stroke and the second one specifying the starting and
        '''     ending vertex for the second stroke.
        '''   </para>
        '''   <para>
        '''     The vertex range specified by each outline should be handled as a single
        '''     line strip (draw a line from the first to the second vertex, then from the
        '''     second to the third, and so on). The final vertex needs to be connected
        '''     to the first vertex again to close the outline.
        '''   </para>
        ''' </remarks>
        Public ReadOnly Property Outlines() As List(Of Outline)
            Get
                Return Me.m_outlines
            End Get
        End Property

        ''' <summary>
        '''   Specifies between which vertices triangles have to be drawn to draw a
        '''   polygon-filled character.
        ''' </summary>
        Public ReadOnly Property Faces() As List(Of Face)
            Get
                Return Me.m_faces
            End Get
        End Property

        ''' <summary>How far to advance the cursor after this character is rendered</summary>
        Private m_advancement As Vector2
        ''' <summary>Vertices used by this character</summary>
        Private m_vertices As List(Of Vector2)
        ''' <summary>Vertex index ranges to use for drawing the character's outlines</summary>
        Private m_outlines As List(Of Outline)
        ''' <summary>Vertex indices to use for filling the character with triangles</summary>
        Private m_faces As List(Of Face)

    End Class

End Namespace